//
//  HZOrderCellModel.m
//  app
//
//  Created by 刘华舟 on 15/5/6.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZOrderCellModel.h"
#import "NSDictionary+SafetyGet.h"

@implementation HZOrderCellModel

+(NSString *)reuseIdentifierOfType:(HZOrderCellType)type
{
    switch (type) {
        case HZOrderCellTypeAddress:
            return @"HZOrderCellAddress";
            
        case HZOrderCellTypeGoods:
            return @"HZOrderCellGoods";
            
        default:
            return @"HZOrderCellThin";
    }
}

+(CGFloat)cellHeightOfType:(HZOrderCellType)type
{
    switch (type) {
        case HZOrderCellTypeAddress:
            return floor(UF(164));
            
        case HZOrderCellTypeGoods:
            return floor(UF(208));
            
        default:
            return floor(UF(104));
    }
};

+(NSInteger)cellUFHeightOfType:(HZOrderCellType)type{
    switch (type) {
        case HZOrderCellTypeAddress:
            return 164;
            
        case HZOrderCellTypeGoods:
            return 208;
            
        default:
            return 104;
    }
}


+ (instancetype)modelWithDictionary:(NSDictionary *)dict type:(HZOrderCellType)type{
    return [[HZOrderCellModel alloc] initModelWithDictionary:dict  type:type];
}
- (instancetype)initModelWithDictionary:(NSDictionary *)dict type:(HZOrderCellType)type{
    if (self = [super init]) {
        
        self.firstOrder = YES;
        self.orderCellType = type;
        
        switch (type) {
            case HZOrderCellTypeAddress:
            {
                self.firstOrder = ![[dict stringForKey:APIKEY_mall_selected nilValue:@"0"] boolValue];
                self.receiver = [dict stringForKey:APIKEY_mall_receiver nilValue:@""];
                self.phone = [dict stringForKey:APIKEY_mall_phone nilValue:@""];
                self.address = [dict stringForKey:APIKEY_mall_fullAddress nilValue:@""];
            };
                break;
            case HZOrderCellTypeThin:
            {
                self.leftTitle = [dict stringForKey:@"leftTitle" nilValue:@""];
                self.rightTitle = [dict stringForKey:@"rightTitle" nilValue:@""];
            };
                break;
            default:
            {
                _actID = [dict stringForKey:APIKEY_mall_act_id nilValue:@"0"];
                _productID = [dict stringForKey:APIKEY_mall_product_id nilValue:@"0"];
                _productTitle = [dict stringForKey:APIKEY_mall_product_title nilValue:@""];
                _productName = [dict stringForKey:APIKEY_mall_product_name nilValue:@""];
                _productNum = [dict stringForKey:APIKEY_mall_product_num nilValue:@"0"];
                _titlePic = [dict stringForKey:APIKEY_mall_title_pic nilValue:@""];
                _salePrice = [dict stringForKey:APIKEY_mall_sale_price nilValue:@""];
                _tagPrice = [dict stringForKey:APIKEY_mall_tag_price nilValue:@""];
                _shopID = [dict stringForKey:APIKEY_mall_shop_id nilValue:@"0"];
                _shopName = [dict stringForKey:APIKEY_mall_shop_name nilValue:@""];
                
                _giftModel = [SNGiftModel modelWithDict:[dict dictForKey:APIKEY_mall_gift]];
                
                
                
                _promotionArray = [dict arrayForKey:APIKEY_mall_promotion];
                
                
                _cellHeight = [UBO_SCREEN uh:[HZOrderCellModel cellUFHeightOfType:HZOrderCellTypeGoods]];
                
                if (_giftModel.gift || _promotionArray.count) {
                    NSInteger col = 0;
                    if (_giftModel) {
                        col = 1;
                    }
//                    if (_promotionArray.count) {
//                        col += 1;
//                    }
                    _cellHeight += [UBO_SCREEN uh:kSizeMallViewMargin oh:kGiftViewHeight*(col)];
                }
                
                _patterns = [NSJSONSerialization JSONObjectWithData:[[dict stringForKey:APIKEY_mall_patterns nilValue:@"[]"] dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];
                
            };
                break;
        }
    }
    
    return self;
}

@end
